package com.fr.report;

import com.fr.base.FCloneable;
import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.base.XMLable;
import com.fr.base.core.FRCoreContext;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.cellElement.Formula;
import com.fr.report.core.FormException;
import com.fr.report.write.BuiltInSQLSubmiter;
import com.fr.report.write.ClassSubmiter;
import com.fr.report.write.FreeSQLSubmiter;
import com.fr.report.write.Submiter;
import com.fr.report.write.ValueVerifier;
import com.fr.util.Utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ReportWriteAttr
  implements XMLable
{
  private List submiterNameList = new ArrayList();
  private List submiterList = new ArrayList();
  private List valueVerifierList = new ArrayList();

  public int getSubmiterCount()
  {
    return this.submiterList.size();
  }

  public Submiter getSubmiter(int paramInt)
  {
    return ((Submiter)this.submiterList.get(paramInt));
  }

  public void addSubmiter(Submiter paramSubmiter)
  {
    this.submiterList.add(paramSubmiter);
    this.submiterNameList.add("");
  }

  public void addSubmiter(String paramString, Submiter paramSubmiter)
  {
    this.submiterList.add(paramSubmiter);
    this.submiterNameList.add(paramString);
  }

  public void clearSubmiters()
  {
    this.submiterList.clear();
    this.submiterNameList.clear();
  }

  public String getSubmiterNameList(int paramInt)
  {
    return ((String)this.submiterNameList.get(paramInt));
  }

  public void addValueVerifier(ValueVerifier paramValueVerifier)
  {
    this.valueVerifierList.add(paramValueVerifier);
  }

  public void removeValueVerifier(int paramInt)
  {
    this.valueVerifierList.remove(paramInt);
  }

  public int getValueVerifierCount()
  {
    return this.valueVerifierList.size();
  }

  public ValueVerifier getValueVerifier(int paramInt)
  {
    return ((ValueVerifier)this.valueVerifierList.get(paramInt));
  }

  public void clearValueVerifiers()
  {
    this.valueVerifierList.clear();
  }

  public void submit(ResultReport paramResultReport, TableDataSource paramTableDataSource, Map paramMap)
    throws FormException
  {
    if (this.submiterList.size() > 0)
    {
      int i = 0;
      int j = this.submiterList.size();
      while (true)
      {
        if (i >= j)
          return;
        if ((!(VT4FR.ADVANCED_ONLINE_WRITE.support())) && (i > 0))
          return;
        Submiter localSubmiter = (Submiter)this.submiterList.get(i);
        try
        {
          localSubmiter.execute(paramResultReport, paramTableDataSource, paramMap);
        }
        catch (Exception localException)
        {
          throw new FormException("submiter error happens.\n" + localException.getMessage(), localException);
        }
        ++i;
      }
    }
    FRContext.getLogger().log(Level.INFO, "No Sumbiter defined!");
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      Object localObject1;
      Object localObject2;
      String str1 = paramXMLableReader.getTagName();
      if ("Submiter".equals(str1))
      {
        localObject1 = null;
        if ((str2 = paramXMLableReader.getAttr("class")) != null)
          localObject1 = str2;
        if (localObject1 == null)
          return;
        localObject2 = null;
        if ((str2 = paramXMLableReader.getAttr("name")) != null)
          localObject2 = str2;
        if (localObject2 == null)
        {
          readOld6_2rcXML(paramXMLableReader);
          return;
        }
        Object localObject3 = null;
        if (((String)localObject1).endsWith(".BuiltInSQLSubmiter"))
          localObject3 = new BuiltInSQLSubmiter();
        else if (((String)localObject1).endsWith(".FreeSQLSubmiter"))
          localObject3 = new FreeSQLSubmiter();
        else if (((String)localObject1).endsWith(".ClassSubmiter"))
          localObject3 = new ClassSubmiter();
        else
          try
          {
            localObject3 = (Submiter)FRCoreContext.classForName((String)localObject1).newInstance();
          }
          catch (Exception localException)
          {
            FRContext.getLogger().log(Level.SEVERE, "Load class with name: " + str2, localException);
          }
        paramXMLableReader.readXMLObject((XMLReadable)localObject3);
        addSubmiter((String)localObject2, (Submiter)localObject3);
      }
      else if ("VV".equals(str1))
      {
        addValueVerifier((ValueVerifier)paramXMLableReader.readXMLObject(new ValueVerifier()));
      }
      else if ("ValueVerifier".equals(str1))
      {
        localObject1 = new ValueVerifier();
        if ((str2 = paramXMLableReader.getAttr("type")) != null)
          ((ValueVerifier)localObject1).setType(Integer.parseInt(str2));
        if ((str2 = paramXMLableReader.getElementValue()) != null)
        {
          localObject2 = Utils.splitString(str2, ",,.,,");
          if ((localObject2 != null) && (localObject2.length == 2))
          {
            ((ValueVerifier)localObject1).setFormula(new Formula(localObject2[0]));
            ((ValueVerifier)localObject1).setMessage(localObject2[1]);
          }
        }
      }
      else if (("WriteSQLAttr".equals(str1)) || ("InsertAttr".equals(str1)))
      {
        localObject1 = new BuiltInSQLSubmiter();
        ((BuiltInSQLSubmiter)localObject1).readOldXML(paramXMLableReader);
        addSubmiter((Submiter)localObject1);
      }
    }
  }

  private void readOld6_2rcXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      Object localObject1;
      Object localObject2;
      String str2 = paramXMLableReader.getTagName();
      if ("Submiter".equals(str2))
      {
        localObject1 = null;
        if ((str1 = paramXMLableReader.getAttr("class")) != null)
          localObject1 = str1;
        if (localObject1 == null)
          return;
        localObject2 = null;
        if (((String)localObject1).startsWith("BuiltInSQLSubmiter"))
        {
          localObject2 = new BuiltInSQLSubmiter();
          if (((String)localObject1).equals("BuiltInSQLSubmiter"))
            addSubmiter(Inter.getLocText("RWA-BuildIn_SQL"), (Submiter)localObject2);
          else
            addSubmiter(((String)localObject1).replaceAll("BuiltInSQLSubmiter", ""), (Submiter)localObject2);
        }
        else if (((String)localObject1).startsWith("FreeSQLSubmiter"))
        {
          localObject2 = new FreeSQLSubmiter();
          if (((String)localObject1).equals("FreeSQLSubmiter"))
            addSubmiter(Inter.getLocText("RWA-Free_SQL"), (Submiter)localObject2);
          else
            addSubmiter(((String)localObject1).replaceAll("FreeSQLSubmiter", ""), (Submiter)localObject2);
        }
        else if (((String)localObject1).startsWith("ClassSubmiter"))
        {
          localObject2 = new ClassSubmiter();
          if (((String)localObject1).equals("ClassSubmiter"))
            addSubmiter(Inter.getLocText("RWA-Class"), (Submiter)localObject2);
          else
            addSubmiter(((String)localObject1).replaceAll("ClassSubmiter", ""), (Submiter)localObject2);
        }
        else
        {
          try
          {
            localObject2 = (Submiter)FRCoreContext.classForName((String)localObject1).newInstance();
          }
          catch (Exception localException)
          {
            FRContext.getLogger().log(Level.SEVERE, "Load class with name: " + str1, localException);
          }
        }
        paramXMLableReader.readXMLObject((XMLReadable)localObject2);
        addSubmiter((Submiter)localObject2);
      }
      else if ("ValueVerifier".equals(str2))
      {
        localObject1 = new ValueVerifier();
        addValueVerifier((ValueVerifier)localObject1);
        if ((str1 = paramXMLableReader.getAttr("type")) != null)
          ((ValueVerifier)localObject1).setType(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getElementValue()) != null)
        {
          localObject2 = Utils.splitString(str1, ",,.,,");
          if ((localObject2 != null) && (localObject2.length == 2))
          {
            ((ValueVerifier)localObject1).setFormula(new Formula(localObject2[0]));
            ((ValueVerifier)localObject1).setMessage(localObject2[1]);
          }
        }
      }
      else if (("WriteSQLAttr".equals(str2)) || ("InsertAttr".equals(str2)))
      {
        localObject1 = new BuiltInSQLSubmiter();
        ((BuiltInSQLSubmiter)localObject1).readOldXML(paramXMLableReader);
        addSubmiter((Submiter)localObject1);
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ReportWriteAttr");
    int i = getSubmiterCount();
    for (int j = 0; j < i; ++j)
    {
      Submiter localSubmiter = getSubmiter(j);
      paramXMLPrintWriter.startTAG("Submiter").attr("class", localSubmiter.getClass().getName()).attr("name", getSubmiterNameList(j));
      localSubmiter.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    j = 0;
    int k = getValueVerifierCount();
    while (j < k)
    {
      ValueVerifier localValueVerifier = getValueVerifier(j);
      localValueVerifier.writeXML(paramXMLPrintWriter);
      ++j;
    }
    paramXMLPrintWriter.end();
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    int i;
    ReportWriteAttr localReportWriteAttr = (ReportWriteAttr)super.clone();
    if (this.submiterList != null)
    {
      localReportWriteAttr.submiterList = new ArrayList();
      for (i = 0; i < this.submiterList.size(); ++i)
        localReportWriteAttr.submiterList.add(((Submiter)this.submiterList.get(i)).clone());
    }
    if (this.submiterNameList != null)
    {
      localReportWriteAttr.submiterNameList = new ArrayList();
      localReportWriteAttr.submiterNameList.addAll(this.submiterNameList);
    }
    if (this.valueVerifierList != null)
    {
      localReportWriteAttr.valueVerifierList = new ArrayList();
      for (i = 0; i < this.valueVerifierList.size(); ++i)
        localReportWriteAttr.valueVerifierList.add(((ValueVerifier)this.valueVerifierList.get(i)).clone());
    }
    return localReportWriteAttr;
  }
}